<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="{$smarty.const.PUBLIC_PATH}js/jquery.min.js"></script>
		<!--<script src="{$smarty.const.PUBLIC_PATH}js/tankClass.js"></script>-->
	</head>
	<body onkeydown="move()" >
		<canvas id="maincan" width="500px" height="500px" style="border: 1px solid red;background-color: black;"></canvas>
		<script src="{$smarty.const.PUBLIC_PATH}js/tankClass.js"></script>
		<script>
			var maincan=document.getElementById("maincan");
			var cxt=maincan.getContext("2d");
			var herobullets=new Array();
			
			var herotank=new hero(10,10,2,5,heroColor);
			var enemytanks=new Array();
			for(var i=0;i<3;i++){
				var enemytank=new enemy((120*i),200,0,5,enemyColor);
				enemytanks[i]=enemytank;
			}
			//刷新作战区域
			function flusharea(){
				cxt.clearRect(0,0,500,500);
				drawtank(herotank);
				drawbullet();
//				console.log(herobullet.x)
				for(var i=0;i<enemytanks.length;i++){
//					randommove(enemytanks[i]);
					//判断是否击中
					if(herobullets.length!=0)
					ishit(herobullets[0],enemytanks[i]);//判断是否击中敌军
					drawtank(enemytanks[i]);
				}
			}
			function enemyrandommove(){
					for(var i=0;i<enemytanks.length;i++){
						randommove(enemytanks[i]);
					}
				}
//			drawtank(enemytank,65);
			flusharea();
			function move(){
				var code=event.keyCode;
				switch(code){
					case 87:
					herotank.moveUp();
					break;
					case 68:
					herotank.moveRight();
					break;
					case 83:
					herotank.moveDown();
					break;
					case 65:
					herotank.moveLeft();
					break;
					case 74:
						if(herobullets.length<1)//最大发射子弹数
						herotank.shot();
					break;
				}
				
				window.setInterval("flusharea()",100);
//				flusharea();
			}
//			window.setInterval("herotank.moveDown()",1000);
			enemyrandommove();
		</script>
	</body>
</html>
